﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class EditCategory : System.Web.UI.UserControl
    {
        public string catename;
        public string image;
        public string description;
        public string showcateleft;
        public int intactivetop;
        public int intactiveleft;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Request.QueryString["catid"] != null)
                {
                    int cateid = Convert.ToInt32(Request.QueryString["catid"]);
                    DataTable dt = DAL.DCollector.DBCollector.Instance.StoredProcedureSelectWhereByID("tbl_CategoryTop", "*", "CategoryTop_ID1", cateid, "selectwhereid");
                    catename = dt.Rows[0]["CategoryTop_Name"].ToString();
                    description = dt.Rows[0]["CategoryTop_Description"].ToString();               

                    txtCateName.Text = catename;
                    CKEditorMota.Text = description;
                }
            }
            catch (Exception)
            {
                Response.Redirect("/error.htm");
            }         
        }

        protected void btnUpdateCate_Click(object sender, EventArgs e)
        {          
                int cateid = Convert.ToInt32(Request.QueryString["catid"]);
                string catename = txtCateName.Text;
                string description = CKEditorMota.Text;    
                if (catename != "")
                {
                   
                        DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[2];
                        cl[0] = new DAL.DHelpers.Column("CategoryTop_Name", catename, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                        cl[1] = new DAL.DHelpers.Column("CategoryTop_Description", description, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);

                        string[] colWhere = new string[1];
                        colWhere[0] = "CategoryTop_ID1";

                        object[] colValue = new object[1];  
                        colValue[0] = cateid;

                        DAL.DCollector.DBCollector.Instance.Update("tbl_CategoryTop", cl, colWhere, colValue);
                        Response.Redirect("/Index.aspx?panel=2&sub=1");
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng nhập tên danh mục...')</script>");
                }                        
        }
    }
}